//
//  Rating.h
//  CLUB_my_part
//
//  Created by Константин Денисов on 8/19/13.
//  Copyright (c) 2013 Константин Денисов. All rights reserved.
//

#ifndef CLUB_my_part_Rating_h
#define CLUB_my_part_Rating_h

//include, define and constants - begin


#include "Player.h"


const double Hunter_Winning_Const = 10.0;

const double Victime_Winning_Const = 20.0;


//include and defines and constants - end
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//all classes, structures and function templates - begin

struct Statistic_Cell
{
    double match_number;
    double hunter_win_number;
    
    Statistic_Cell();
};


void Recount_Rating(PPlayer Hunter, PPlayer Victim, bool hunt_result);


int Class_To_Int(Classes converted_class);


//all classes and structures and function templates - end
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//global var - begin


Statistic_Cell Statistic_Table[Number_Of_Classes][Number_Of_Classes];

Statistic_Cell Global_Score;

double Procent_Of_Good_Players_Wins = 5.0;


//global var - end
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//all rating functions - begin


void Recount_Rating(PPlayer Hunter, PPlayer Victim, bool hunt_result)
{
    double shift = 1.0;
    
    if (hunt_result)
    {
        shift *= (Global_Score.match_number - Global_Score.hunter_win_number) /
                 Global_Score.hunter_win_number;
        
        shift *= (Global_Score.hunter_win_number * Statistic_Table[Class_To_Int(Hunter->player_class)]
                  [Class_To_Int(Victim->player_class)].match_number) /
                 (Statistic_Table[Class_To_Int(Hunter->player_class)][Class_To_Int(Victim->player_class)].
                  hunter_win_number * Global_Score.match_number);
        
        //надо ещё домножить
        
        Hunter->rating += shift;
        Victim->rating -= shift;
    }
    else
    {
        Hunter->rating -= shift;
        Victim->rating += shift;
    }
}


int Class_To_Int(Classes converted_class)
{
    switch (converted_class)
    {
        case Warrior:
            return 0;
            break;
            
        case Druid:
            return 1;
            break;
            
        case Necromancer:
            return 2;
            break;
            
        case Storm_Sorcerer:
            return 3;
            break;
            
        default:
            return 0;
            break;
    }
}


Statistic_Cell::Statistic_Cell()
{
    match_number = 0;
    hunter_win_number = 0;
}


//all rating functions - end

#endif
